package org.dromara.common.core.utils;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.util.Base64;

public class ImageUtil {
    /**
     * @param file base64编码字符串
     * @Description: 将base64编码字符串转换为图片
     */
    public static String generateImage(String file) {
        File tempFile = FileUtil.createTempFile("", ".jpg", true);
        String base64Data = file.substring(file.indexOf(",") + 1);
        byte[] imageBytes = Base64.getDecoder().decode(base64Data);
        FileUtil.writeBytes(imageBytes, tempFile);
        return tempFile.getAbsolutePath();
    }
}

